@extends('home.base.headers')

@section('content')

<div class="hr-10"></div>
<div class="g">
	<!--面包屑 -->
<div class="breadcrumb-area"><a href="{{ asset('/') }}" title="首页">首页</a>&nbsp;&nbsp;\&nbsp;&nbsp;<em id="personCenter"></em><em id="pathPoint">&nbsp;&nbsp;\&nbsp;&nbsp;</em><span id="pathTitle">收货地址管理</span></div>	
</div>
<div class="hr-10"></div>

<div class="g">
    <div class="fr u-4-5"><!-- 20141212-栏目-start -->
<div class="section-header">
    <div class="fl">
        <h2><span>收货地址管理</span></h2>
    </div>
</div><!-- 20141212-栏目-end -->
<div class="hr-20"></div>
<!-- 20141216-我的收货地址-表单-编辑地址-start -->
<div class="myAddress-edit" id="myAddress-edit">
    <div class="form-edit-panels" id="form-edit-panels">
	    <form id="myAddress-form" action="/address" autocomplete="off" method="post"  data-type="add">
        {{ csrf_field() }}
            <div class="form-edit-table">
                <table border="0" cellpadding="0" cellspacing="0">
                	<tbody>
                        <tr>
                            <th><span class="required">*</span><label for="consignee">寄件人：</label></th>
                            <td>
                                <input maxlength="20" type="text" name="uid" id="consignee" class="text span-130" validator="validator11482158056572" value="{{ session('user')->userName }}" disabled="disabled">
                                <label id="consignee-msg"></label>
                            </td>
                        </tr>
                        <tr>
                            <th><span class="required">*</span><label for="consignee">收货人：</label></th>
                            <td>
                            	<input maxlength="20" type="text" name="consignee" id="consignee" class="text span-130" validator="validator11482158056572">
                            	<label id="consignee-msg"></label>
                            </td>
                        </tr>
                        <tr>
                            <th><span class="required">*</span><label for="consignee">收货地址：</label></th>
                            <td>
								<div id="myAddress-region" class="inline-block"><span class="ol_linkSelect ol_linkSelect_region">
                                <select id="cid" name="city1" class="ec_linkSelect">
                                    <option>---请选择---</option>
                                </select></span></div>
								<label id="myAddress-msg"></label>
							</td>
                        </tr>
                        <tr class="tr-rel">
                            <th><span class="required">*</span><label for="consignee">详细地址：</label></th>
                            <td>
                            	<div class="inline-block relative">
                            		<label style="display: block; position: absolute; cursor: text; float: left; z-index: 2; color: rgb(153, 153, 153);" class="textarea span-480" for="address"></label><textarea name="detailAddress" id="address" maxlength="100" class="textarea span-480" validator="validator21482158056572" style="z-index: 1;"></textarea>
                            	</div>
                            	<label class="vat" id="address-msg"></label>
                            </td>
                        </tr>
                        <tr>
                            <th><span class="required">*</span><label for="mobile">手机号码：</label></th>
                            <td>
								<div class="inline-block vam"><input maxlength="15" type="text" name="consigneePhone" id="mobile" class="text span-130 ime-disabled" alt="tel-msg" validator="validator41482158056584"></div>
								<div><label id="tel-msg"></label></div>
			    			</td>
                        </tr>
                        <tr class="tr-action">
                        	<th>&nbsp;</th>
                        	<td>
                                <input type="submit" value="添加新地址">
                        	</td>
                        </tr>
                    </tbody>
                </table>
            </div>

	    </form>
    </div>
</div>
<!-- 20141216-我的收货地址-表单-编辑地址-end -->
<div class="hr-30"></div>
<!-- 20141216-我的收货地址-列表-start -->
<!--表单-我的收货地址 -->
<div class="myAddress-record" id="myAddress-record" style="display: block">
 <form action="" method="post" name="myform">
        {{ csrf_field() }}
        {{ method_field('DELETE') }}
        <!-- <input type='hidden' name='_token' value='{{ csrf_token() }}'>
        <input type='hidden' name='_method' value='delete'> -->
    </form>
	<div class="list-group-title">

		<table border="0" cellspacing="5">
			<thead>
				<tr>
                    <th>寄件人</th>
					<th>收货人</th>
					<th>收货地址</th>
					<th>手机/电话</th>
                    <th>是否设为默认</th>
					<th>操作</th>
				</tr>
			</thead>
            @foreach ($list as $v)
              <tr>
                  <td>{{ $v->userName }}</td>
                  <td>{{ $v->consignee }}</td>
                  <td>{{ $v->province.$v->city.$v->country.$v->town.$v->detailAddress }}</td>
                  <td>{{ $v->consigneePhone }}</td>
                  <td>{{ $v->defaultAddress == 1?'默认':'不默认' }}</td>
                  <td>
                    <!-- <a href="/address/{{ $v->id }}/edit">默认</a> /  -->
                    <a href="/address/{{ $v->id }}/edit">修改</a> / 
                    <a href="javascript:doDel({{ $v->id }})">删除</a>

                 </td>
              </tr>
           @endforeach
 <!--        </tbody> -->
		</table>
	</div>	
    <center>{{ $list->links() }}</center>
</div> 

<script type="text/javascript">
        function doDel(id)
        {
            if(confirm('确定要删除吗？')){
                var form = document.myform;
                form.action = '/address/'+id;
                form.submit();
            }
        }
    </script>

<script src="{{ asset('home/js/address.min.js') }}"></script><script id="jsapi_loader0" loadtype="insert" type="text/javascript" src="{{ asset('home/js/jquery.form-2.49.js') }}" charset="utf-8"></script><script>(function(){var time = 0,el = document.getElementById('jsapi_loader0');if(!el || (el.readyState && 'complete' != el.readyState)){ if(time<10){ setTimeout(arguments.callee,30); time++; }else{ logger.error('load the script of id jsapi_loader0 fail!');} return; }ol._setLoadStatus("jquery.form","complete");})();</script><script id="jsapi_loader1" loadtype="insert" type="text/javascript" src="{{ asset('/home/js/ajax.js') }}" charset="utf-8"></script><script>(function(){var time = 0,el = document.getElementById('jsapi_loader1');if(!el || (el.readyState && 'complete' != el.readyState)){ if(time<10){ setTimeout(arguments.callee,30); time++; }else{ logger.error('load the script of id jsapi_loader1 fail!');} return; }ol._setLoadStatus("ajax","complete");})();</script><script id="jsapi_loader2" loadtype="insert" type="text/javascript" src="{{ asset('home/js/box-min.js') }}"></script><script>(function(){var time = 0,el = document.getElementById('jsapi_loader2');if(!el || (el.readyState && 'complete' != el.readyState)){ if(time<10){ setTimeout(arguments.callee,30); time++; }else{ logger.error('load the script of id jsapi_loader2 fail!');} return; }ol._setLoadStatus("ec.box/box-min.js","complete");})();</script><script id="jsapi_loader3" loadtype="insert" type="text/javascript" src="{{ asset('/home/js/region-min.js') }}" charset="utf-8"></script><script>(function(){var time = 0,el = document.getElementById('jsapi_loader3');if(!el || (el.readyState && 'complete' != el.readyState)){ if(time<10){ setTimeout(arguments.callee,30); time++; }else{ logger.error('load the script of id jsapi_loader3 fail!');} return; }ol._setLoadStatus("linkSelect/region-min.js?20161011","complete");})();</script><script id="jsapi_loader4" loadtype="insert" type="text/javascript" src="{{ asset('/home/js/bigInt.min.js') }}"></script><script>(function(){var time = 0,el = document.getElementById('jsapi_loader4');if(!el || (el.readyState && 'complete' != el.readyState)){ if(time<10){ setTimeout(arguments.callee,30); time++; }else{ logger.error('load the script of id jsapi_loader4 fail!');} return; }ol._setLoadStatus("dh/bigInt.min.js","complete");})();</script><script id="jsapi_loader5" loadtype="insert" type="text/javascript" src="{{ asset('/home/js/aes.js') }}"></script><script>(function(){var time = 0,el = document.getElementById('jsapi_loader5');if(!el || (el.readyState && 'complete' != el.readyState)){ if(time<10){ setTimeout(arguments.callee,30); time++; }else{ logger.error('load the script of id jsapi_loader5 fail!');} return; }ol._setLoadStatus("aes/aes.js","complete");})();</script><script id="jsapi_loader6" loadtype="insert" type="text/javascript" src="{{ asset('/home/js/aesUtil.js') }}"></script><script>(function(){var time = 0,el = document.getElementById('jsapi_loader6');if(!el || (el.readyState && 'complete' != el.readyState)){ if(time<10){ setTimeout(arguments.callee,30); time++; }else{ logger.error('load the script of id jsapi_loader6 fail!');} return; }ol._setLoadStatus("aes/aesUtil.js","complete");})();</script><script id="jsapi_loader7" loadtype="insert" type="text/javascript" src="{{ asset('/home/js/pbkdf2.js') }}"></script><script>(function(){var time = 0,el = document.getElementById('jsapi_loader7');if(!el || (el.readyState && 'complete' != el.readyState)){ if(time<10){ setTimeout(arguments.callee,30); time++; }else{ logger.error('load the script of id jsapi_loader7 fail!');} return; }ol._setLoadStatus("aes/pbkdf2.js","complete");})();</script><script id="jsapi_loader8" loadtype="insert" type="text/javascript" src="{{ asset('/home/js/rc4.js') }}"></script><script>(function(){var time = 0,el = document.getElementById('jsapi_loader8');if(!el || (el.readyState && 'complete' != el.readyState)){ if(time<10){ setTimeout(arguments.callee,30); time++; }else{ logger.error('load the script of id jsapi_loader8 fail!');} return; }ol._setLoadStatus("crypt/rc4.js","complete");})();</script></div>
	

<div class="fl u-1-5">
    <!--左边菜单 -->
<div class="mc-menu-area">
    <div class="h"><a href="http://www.vmall.com/member?t=1482158047603" class="button-go-mc" title="我的商城"><span>我的商城</span></a></div>
    <div class="b">
        <ul>
            <li>
                <h3>
                    <span>订单中心</span>
                </h3>
                <ol>
                    <li id="li-order"><a href="http://www.vmall.com/member/order?t=1482158047603" title="我的订单"><span>我的订单</span></a></li>
                    <li id="li-exchange"><a href="http://www.vmall.com/member/exchange?t=1482158047603" title="我的退换货"><span>我的退换货</span></a></li>
                    <li id="li-groupBuyRecord"><a href="http://www.vmall.com/member/groupBuyRecord?t=1482158047603" title="我的团购"><span>我的团购</span></a></li>
                    <li id="li-recover"><a href="http://www.vmall.com/member/recycle/index?t=1482158047603" title="我的回收单"><span>我的回收单</span></a></li>
                </ol>
            </li>
            <li>
                <h3>
                    <span>个人中心</span>
                </h3>
                <ol>
                    <li id="li-myAppointment"><a href="http://www.vmall.com/member/myAppointment?t=1482158047603" title="我的预约"><span>我的预约</span></a></li>
                    <li id="li-notification"><a href="http://www.vmall.com/member/notification?t=1482158047603" title="到货通知"><span>到货通知</span></a></li>
                    <li id="li-point"><a href="http://www.vmall.com/member/point?t=1482158047603" title="等级与特权"><span>等级与特权</span></a></li>
                    <li id="li-newpoint"><a href="http://www.vmall.com/member/newpoint?t=1482158047603" title="我的积分"><span>我的积分</span></a></li>
                    <li id="li-zhima"><a href="http://www.vmall.com/member/zm?t=1482158047603" title="芝麻信用"><span>芝麻信用</span></a></li>
                    <li id="li-authentication"><a href="http://www.vmall.com/authmember/accesstoken?t=1482158047603" title="实名认证"><span>实名认证</span></a></li>
                    <li id="li-balance"><a href="http://www.vmall.com/member/balance?t=1482158047603" title="代金券"><span>代金券</span></a></li>
                    <li id="li-petal"><a href="http://www.vmall.com/member/petal?t=1482158047603" title="我的花瓣"><span>我的花瓣</span></a></li>
                    <li id="li-coupon"><a href="http://www.vmall.com/member/coupon?t=1482158047603" title="我的优惠劵"><span>我的优惠劵</span></a></li>
                    <li id="li-enterprise" class="hide"></li>
                    <li id="li-myAddress" class="current"><a href="http://www.vmall.com/member/myAddress?t=1482158047603" title="收货地址管理"><span>收货地址管理</span></a></li>
                    <!--  
                    <li id="li-zp"><a href="/member/invoiceQualifications/view?t=1482158047603" title="专票资质"><span>专票资质</span></a></li>
                    -->
                </ol>
            </li>
            <li>
                <h3>
                    <span>社区中心</span>
                </h3>
                <ol>
                    <li id="li-prdRemark"><a href="http://www.vmall.com/member/prdRemarkView?t=1482158047603" title="商品评价"><span>商品评价</span></a></li>
                    <li id="li-msg"><a href="http://www.vmall.com/member/msg?t=1482158047603" title="站内信"><span>站内信</span></a></li>
                </ol>
            </li>
        </ul>
    </div>
    <div class="f"></div>
</div>
    </div>
</div>
<div class="hr-80"></div>

 <script src="{{ asset('/home/js/jquery-1.8.3.min.js') }}"></script>
    <script type="text/javascript">
        $.ajax({
            url:'/doget',
            type:'get',
            async:true,
            data:{upid:0},
            dataType:'json',
            
            success:function(data)
            {
                for (var i = 0; i < data.length; i++) {
                    $('#cid').append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                };
            },
            error:function()
            {
                alert('ajax请求失败');
            }
        });
        
        var num = 2;
        $("select").live("change",function(){
            //删除掉选择的select后面所有的select
            $(this).nextAll('select').remove();
            //获取选择的select的值
            var ob = $(this).val();
            //判断是不是选择的默认，如果是默认就不执行ajax
            if(ob != '---请选择---'){
                //把当前对象保存下来，拿到ajax回调函数中使用
                var sel = $(this);

                //发送ajax
                $.ajax({
                    url:'/dopost',
                    type:'post',
                    async:true,
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    data:{upid:ob},
                    dataType:'json',
                    success:function(data)
                    {
                        // console.log(data);
                        //如果返回的数组长度=0,说明没有下一个select
                        if(data.length>0){
                            //生成一个新的select
                            var select = $("<select name=city"+num+"><option>---请选择---</option></select>");
                            // console.log(data);
                            //把返回回来的数据遍历成option追加到新生成的select内
                            for (var i = 0; i < data.length; i++) {
                                $(select).append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                            };
                            //把新生成的select追加到上一个select的后边
                            sel.after(select);      
                            num++;
                        }
                    },
                    error:function()
                    {
                        alert('ajax请求失败');
                    }
                });
            }
        });
    </script>
@endsection
